home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / AMOSList / AMOSLIST / text0105.txt < prev    next >
Encoding:
Text File  |  1998-04-01  |  2.0 KB  |  62 lines

  1. > why does this cause me to get an "Out of stack space" Error and
  2. > what can I do to remedy it?
  3. -----<Program (slightly "compressed") follows>-----
  4. > S1
  5. > Procedure S1
  6. >    Paper 0 : Centre "Procedure S1 Here!"
  7. >    Wait 1 :  Cls 0 : S2
  8. > End Proc
  9. > Procedure S2
  10. >    Paper 0 : Centre "Procedure S2 Here!"
  11. >    Wait 1 : Cls 0 : S1
  12. > End Proc
  13. > Do : Loop 
  14.  
  15.    Well, stack space is limited.  The program begins by calling the
  16.    procedure S1 which in turn calls procedure S2 which calls
  17.    procedure S1 which calls procedure S2 calls S1 calls S2 calls
  18.    S1 calls S2 S1 S2 S1 S2 S1 S2... Phew - finally broke out!!
  19.  
  20.    Everytime you call a procedure (or Gosub a routine) some data is
  21.    pushed onto the stack, at the end of the procedure this data is
  22.    retrieved from the stack.  However, both of your procedures are
  23.    calling each other instead of exiting, so the data is never removed
  24.    from the stack where it keeps accumulating until finally you have
  25.    completely filled all available stack space...
  26.  
  27.    How can you remedy this?
  28.    Well, you need to take a good look at what you're trying to do...
  29.    why do you want these procedures to call each other in an endless
  30.    loop like that?
  31.  
  32.    If you're trying for some type of recursion, you need to insert a
  33.    counter in these procedures some place.
  34.  
  35. -----<REVISED CODE BEGINS HERE>-----
  36. GLOBAL COUNTER
  37. Procedure S1
  38.    Paper 0 : Centre "Procedure S1 Here!"
  39.    Wait 1 :  Cls 0
  40.    S2
  41. End Proc
  42. Procedure S2
  43.    Paper 0 : Centre "Procedure S2 Here!"
  44.    Wait 1 : Cls 0 : S1
  45.    Inc COUNTER
  46.    If COUNTER<5 Then S1
  47. End Proc
  48. COUNTER=0 : S1
  49. Do
  50. Loop 
  51. -----<REVISED CODE ENDS HERE>---
  52.  
  53.    Of course, as usual I'm typing this on my PC, so I don't really know
  54.    how well this will work... ;-)  You need to determine exactly what
  55.    it is you're trying to accomplish as there is most likely a better
  56.    way to achieve what you're after. :-)
  57.  
  58.  
  59.                 Garfield Benjamin    e-mail:gbenjam@sosbbs.com
  60.         Website( http://www.sosbbs.com/~gbenjam ): 50% Complete
  61.  
  62.